package acm.蓝桥杯模拟;

import java.util.Scanner;

public class TT {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        int[] dp = new int[n];
        for (int i = 0; i < dp.length; i++) {
            dp[i] = sc.nextInt();
        }
        int max= Integer.MIN_VALUE; //最大极小值
        int min= Integer.MAX_VALUE;//最小极大值
        for (int l = 0,r=2; r < n; l++,r++) {
            if (dp[r-1]>dp[l]&&dp[r-1]>dp[r]){  //极大值
                min=Math.min(min,dp[r-1]);
            }else if (dp[r-1]<dp[l]&&dp[r-1]<dp[r]){    //极小值
                max=Math.max(max,dp[r-1]);
            }
        }
        System.out.println(max+" "+min);
    }
}
